﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTO
{
	public class ChucVuDTO
	{

		//////////////////////////////////////////////////////////

		                                                          

		//            Enter code your here                      //

		                                                          

		//////////////////////////////////////////////////////////
	

		private int m_MaChucVu;
		private string m_TenChucVu;

		public  int MaChucVu
		{
			get { return this.m_MaChucVu; }
			set { this.m_MaChucVu = value; }
		}


		public  string TenChucVu
		{
			get { return this.m_TenChucVu; }
			set { this.m_TenChucVu = value; }
		}

		public static readonly string DisplayMember ="TenChucVu";

		public static readonly string ValueMember ="MaChucVu";

	}

}


/*

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;

namespace _1042009_1042034
{
    public partial class uctCapNhatDanhMucPhong : UserControl
    {
        public uctCapNhatDanhMucPhong()
        {
            InitializeComponent();
        }
        
        int iColStt, iColMaPhong, iColTenPhong, iColMaLoaiPhong, iColDonGia, iColMaTinhTrang, iColGhiChu, iColCheck;
        protected void CreateColumn()
        {
            this.dgv.Columns.Clear();
            
            DataTable DataLoaiPhong = Business.LoaiPhongService.ConvertListLoaiPhongDTOToDataTable(ListLoaiPhong);
            DataTable DataTinhTrang = Business.TinhTrangService.ConvertListTinhTrangDTOToDataTable(ListTinhTrang);         
            DataTable DataPhong = Business.PhongService.ConvertListPhongDTOToDataTable(ListPhong);
            this.dgv.MyDataTable = DataPhong;

            this.dgv.AddTextColumn(true, "STT", "STT");
            this.dgv.AddTextColumn(true,"MaPhong", "Mã Phòng");
            this.dgv.AddTextColumn(false, "TenPhong", "Tên Phòng");
            this.dgv.AddComboBoxColumns(false, "MaLoaiPhong", "Loại Phòng", DataLoaiPhong, LoaiPhongDTO.ValueMember, LoaiPhongDTO.DisplayMember);
            this.dgv.AddComboBoxColumns(true, "DonGia", "Đơn Giá", DataLoaiPhong, LoaiPhongDTO.ValueMember, "DonGia");
            this.dgv.AddTextColumn(false, "GhiChu", "Ghi Chú");
            this.dgv.AddComboBoxColumns(false, "MaTinhTrang", "Tình Trạng", DataTinhTrang, TinhTrangDTO.ValueMember, TinhTrangDTO.DisplayMember);
            this.dgv.AddCheckBoxColumn("Check", "Check");

            iColStt = this.dgv.GetColumIndexByName("STT");
            iColMaPhong = this.dgv.GetColumIndexByName("MaPhong");
            iColTenPhong = this.dgv.GetColumIndexByName("TenPhong");
            iColMaLoaiPhong = this.dgv.GetColumIndexByName("MaLoaiPhong");
            iColMaTinhTrang = this.dgv.GetColumIndexByName("MaTinhTrang");
            iColGhiChu = this.dgv.GetColumIndexByName("GhiChu");
            iColCheck = this.dgv.GetColumIndexByName("Check");
            iColDonGia = this.dgv.GetColumIndexByName("DonGia");
        }
            
        protected void LoadRows(int iRow)
        {
            this.dgv.Rows[iRow].ReadOnly = false;
             //coi no dang o trang may
            int Start = (this.dgv.iPage - 1) * this.dgv.iRecord + iRow;
            int Stt = Start + 1;
            string[] lst = new string[] {Stt.ToString(),
                this.dgv.MyDataTable.Rows[Start]["MaPhong"].ToString(),                
                this.dgv.MyDataTable.Rows[Start]["TenPhong"].ToString(),
                this.dgv.MyDataTable.Rows[Start]["MaloaiPhong"].ToString(),/////2 cot dung chung 1 Datasource
                this.dgv.MyDataTable.Rows[Start]["MaloaiPhong"].ToString(),/////
                this.dgv.MyDataTable.Rows[Start]["GhiChu"].ToString(),
                this.dgv.MyDataTable.Rows[Start]["MaTinhTrang"].ToString(),
                "Unchecked"};
            this.dgv.Rows[iRow].SetValues(lst);
            this.dgv.SetRowColor(iRow,MyColor.Default);
        }

        void SetUpForm()
        {
            this.AutoSize = false;
            this.AutoScroll = false;
            this.Size = Form1.SizeContext;
        }
        protected void SetUpDataGridView()
        {
            this.dgv.iRecord = 7;
            this.dgv.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
            this.dgv.ScrollBars = ScrollBars.Horizontal;
            this.dgv.TopLeftHeaderCell.Value = "Select All";
            this.dgv.AutoSize = false;
            // dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader; 
           //khong cho hien dong trang.
            this.dgv.AllowUserToAddRows = false; 
        }

        protected void ReLoad()
        {
            this.dgv.m_Reload = true;
            //cap nhat lai trang.
            uctPhanTrang1.Refresh();
            this.dgv.AddRows();
            if (this.dgv.MyDataTable != null)
            {
                int Start = this.dgv.iRecord * (this.dgv.iPage - 1);
                int iRow = 0;
                for (int i = Start; i < Start + this.dgv.iRecord; i++)
                {
                    if (i < this.dgv.MyDataTable.Rows.Count)
                    {
                        this.LoadRows(iRow);
                        iRow++;
                    }
                }
            }
        }

        int iTongSoBoDuLieu = 0;


        List<PhongDTO> ListPhong;
        List<PhongDTO> ListPhongDuTru;
        List<LoaiPhongDTO> ListLoaiPhong;
        List<TinhTrangDTO> ListTinhTrang;

        private void UctDanhMucPhong_Load(object sender, EventArgs e)
        {
            //lay data
            ListPhong = Business.PhongService.LayDanhSach();
            ListPhongDuTru = Business.PhongService.LayDanhSach();
            ListLoaiPhong = Business.LoaiPhongService.LayDanhSach();
            ListTinhTrang = Business.TinhTrangService.LayDanhSach();

            ////////////////
            this.SetUpDataGridView();
            this.CreateColumn();
            this.ReLoad();
            this.SetUpForm();
            //su kien
            this.dgv.CellValueChanged += new DataGridViewCellEventHandler(dgv_CellValueChanged);
            
            //click thay doi trang.
            this.iTongSoBoDuLieu = Business.PhongService.Count();
            this.uctPhanTrang1.SetValue(iTongSoBoDuLieu, this.dgv.iRecord);
            this.uctPhanTrang1.OnPageClick += new uctPhanTrang.PageClick(uctPhanTrang1_OnPageClick);
        }      

        void uctPhanTrang1_OnPageClick(int Page)
        {
            this.dgv.iPage = Page;
            this.ReLoad();
        }


        void dgv_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            int ColIndex = this.dgv.SelectedCells[0].ColumnIndex;
            int RowIndex = this.dgv.SelectedCells[0].RowIndex;

            if (this.dgv.Rows[RowIndex].ReadOnly == true)
            {
                return;
            }            

            if (ColIndex == this.iColMaLoaiPhong)
            {
                this.dgv.Rows[RowIndex].Cells[ColIndex + 1].Value = this.dgv.Rows[RowIndex].Cells[ColIndex].Value;
            }
            if (ColIndex != 0)
            {
                this.dgv.SetRowColor(RowIndex, MyColor.Edit);
            }
            if (ColIndex != this.iColCheck && ColIndex != this.iColStt)
            {
                this.dgv.Rows[RowIndex].Cells[this.iColCheck].Value = "Checked";
            }
        }
                
        PhongDTO GetDataOfRows(int iRow)
        {
            PhongDTO p = new PhongDTO();

            p.MaPhong = int.Parse(this.dgv.Rows[iRow].Cells[iColMaPhong].Value.ToString());
            p.MaLoaiPhong = int.Parse(this.dgv.Rows[iRow].Cells[iColMaLoaiPhong].Value.ToString());
            p.MaTinhTrang = int.Parse(this.dgv.Rows[iRow].Cells[iColMaTinhTrang].Value.ToString());
             
            p.TenPhong = "";
            if( this.dgv.Rows[iRow].Cells[iColTenPhong].Value != null)
            {
                p.TenPhong = (this.dgv.Rows[iRow].Cells[iColTenPhong].Value.ToString());
            }
            p.GhiChu = "";   
            if( this.dgv.Rows[iRow].Cells[iColGhiChu].Value != null)
            {
                p.GhiChu = (this.dgv.Rows[iRow].Cells[iColGhiChu].Value.ToString());
            }
            return p;
        }
        void UpdateDataSource(int iRow, PhongDTO obj)
        {
            int Start = (this.dgv.iPage - 1) * this.dgv.iRecord + iRow;
            this.dgv.MyDataTable.Rows[Start][1] = obj.TenPhong.ToString();
            this.dgv.MyDataTable.Rows[Start][2] = obj.MaLoaiPhong.ToString();
            this.dgv.MyDataTable.Rows[Start][3] = obj.GhiChu.ToString();
            this.dgv.MyDataTable.Rows[Start][4] = obj.MaTinhTrang.ToString();
        }
        
        List<PhongDTO> ListRowsChange = new List<PhongDTO>();
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            int CheckColIndex = this.iColCheck;
            PhongDTO objPhong = new PhongDTO();
            int Dem = 0;
            for (int i = 0; i < this.dgv.Rows.Count; i++)
            {
                if (this.dgv.Rows[i].Cells[CheckColIndex].Value != null)
                {
                    if (this.dgv.Rows[i].Cells[CheckColIndex].Value.ToString() == "Checked")
                    {
                        try
                        {
                            objPhong = this.GetDataOfRows(i);
                        }
                        catch
                        {
                            this.dgv.SelectedColumns[this.iColCheck].Selected = true;
                            this.dgv.Rows[i].Cells[this.iColCheck].Value = "Unchecked";
                            continue;
                        }
                        if (objPhong.KiemTra() == false)
                        {
                            this.dgv.SetRowColor(i, MyColor.Eror);
                        }
                        else
                        {
                            //Business.PhongService.CapNhat(objPhong);
                            //cập nhật lại datasource, chua cap nhat lai DataBase
                            this.UpdateDataSource(i, objPhong);
                            this.dgv.Rows[i].Cells[this.iColCheck].Selected = true;
                            this.dgv.Rows[i].Cells[this.iColCheck].Value = "Unchecked";
                            int iRecord = i + (this.dgv.iPage - 1)*this.dgv.iRecord;
                            int index = Business.PhongService.KiemTraMaPhongTrongListPhong(objPhong.MaPhong, this.ListRowsChange);
                            if (index >= 0)
                            {
                                this.ListRowsChange.RemoveAt(index);
                            }
                            this.ListRowsChange.Add(objPhong);
                            Dem++;
                        }
                    }
                }
            }
            if (Dem > 0)
            {
                MessageBox.Show("Đã cập nhật lại dữ liệu trên Form");
            }
        }
        List<PhongDTO> ListRowsRemove = new List<PhongDTO>();
        
        void RemoveRow(int iRow)
        {
            //xoa trong List
            try
            {
                int iCount = (this.dgv.iPage - 1) * this.dgv.iRecord + iRow;

                //add vao danh sach xoa
                this.ListPhong.RemoveAt(iCount);

                this.iTongSoBoDuLieu--;
                this.uctPhanTrang1.SetValue(iTongSoBoDuLieu, this.dgv.iRecord, this.dgv.iPage);
                this.dgv.iPage = this.uctPhanTrang1.GetPageIndex();
            }
            catch { }
            //xoa DataSource
            this.dgv.RemoveRows(iRow);
        }
        private void btnXoa_Click(object sender, EventArgs e)
        {
            int CheckColIndex = this.iColCheck;
            int Dem = 0;
            for (int i = this.dgv.Rows.Count - 1; i >= 0; i--)
            {
                if (this.dgv.Rows[i].Cells[CheckColIndex].Value != null)
                {
                    if (this.dgv.Rows[i].Cells[CheckColIndex].Value.ToString() == "Checked")
                    {
                        //luu vao ListXoa
                        PhongDTO PhongXoa = this.GetDataOfRows(i);
                        if (Business.PhongService.KiemTraMaPhongTrongListPhong(PhongXoa.MaPhong, this.ListRowsRemove) == -1)
                        {
                            this.ListRowsRemove.Add(PhongXoa);
                        }
                        Dem++;
                        //tien hanh xoa du lieu tren form
                        this.RemoveRow(i);
                    }
                }
            }
            if (Dem > 0)
            {
                this.ReLoad();
            }
        }        
        private void btnCapNhatCSDL_Click(object sender, EventArgs e)
        {           
            //Cap nhat
            for (int i = 0; i < this.ListRowsChange.Count; i++)
            {
                Business.PhongService.CapNhat(this.ListRowsChange[i]);
            }
            //Cap nhat
            for (int i = 0; i < this.ListRowsRemove.Count; i++)
            {
                Business.PhongService.Xoa(this.ListRowsRemove[i].MaPhong);
            }
            this.ListRowsChange.Clear();
            this.ListRowsRemove.Clear();
            MessageBox.Show("Đã ghi xuống CSDL");
        }

        void PhucHoiDuLieuTrenForm()
        {
            for (int i = 0; i < this.ListPhong.Count; i++)
            {
                Business.PhongService.CapNhat(this.ListPhong[i]);
            }
            //cap nhat lai Data cua dgv

           // this.bReLoadDataSource = true;
        }
        private void btnPhucHoiCSDL_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Chỉ phục hồi những dữ liệu bị thay đổi, không phục hồi dữ liệu đã xóa", "Phục hồi dữ liệu đã cập nhật", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                for (int i = 0; i < this.ListPhong.Count; i++)
                {
                    //phuc hoi CSDL
                    Business.PhongService.CapNhat(this.ListPhong[i]);

                    //kho a nha. phuc hoi tren form.
                    this.PhucHoiDuLieuTrenForm();
                }

            ///phuc hoi nhung bo du lieu da xoa tren form nhung chua ghi vao CSDL

                for( int i = 0; i <  this.ListRowsRemove.Count; i++)
                {
                    int index = Business.PhongService.TimViTriPhongTrongListPhong(this.ListRowsRemove[i].MaPhong, this.ListPhongDuTru);
                    if (index > -1)
                    {
                        this.ListPhong.Add(this.ListPhongDuTru[index]);
                        this.iTongSoBoDuLieu++;
                        this.uctPhanTrang1.SetValue(iTongSoBoDuLieu, this.dgv.iRecord);
                    }
                }
                this.ListRowsChange.Clear();
                this.ListRowsRemove.Clear();
                this.dgv.iPage = 1;
                this.ReLoad();
            }
        }        
    }
}

*/